﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NetfractionHub.LocalMachine.BotCommands;
using NetfractionHub.Network.Protocol;
using NetfractionHub.Network.Protocol.BASE.Factory;
using NetfractionHub.Network.Protocol.UCMD;
using NetfractionHub.Network.Protocol.UCMD.Factory;

namespace AnnouncerBot.Handlers
{
    [CommandHandler("listcategories")]
    [UserCommand("List Categories", FactoryCMD.ConextTypesEnum.HubCommand, "HMSG {0}listcategories\n")]
    public class ListCategories : CommandHandler
    {
        public override BotReturnStatus HandleCommandMessage(NetfractionHub.RemoteMachine.Node source, CommandMessage message)
        {
            Community.CsharpSqlite.SQLiteClient.SqliteDataReader sdr = AnnouncerBot.DataStore.ExecuteQuery("SELECT CategoryId, Name FROM Categories");
            if (sdr != null)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("Available categories are:");
                while (sdr.Read())
                {
                    sb.AppendLine(String.Format("{0}: {1}", sdr.GetInt32(0), sdr.GetString(1)));
                }
                return new BotReturnStatus(true, sb.ToString().TrimEnd(new char[] { '\n' }));
            }

            return true;
        }
    }
}
